
define(
   [
      'dojo/_base/declare',
      'dojo/_base/lang',
      'dojo/topic',
      'dijit/layout/ContentPane',
      'noBusinessBase/gui/AjaxResult'
   ],
   function(declare, lang, topic, BaseCp, GuiAjaxResult)
   {
      return declare([BaseCp, GuiAjaxResult],
      {
         constructor: function(args)
         {
            dojo.safeMixin(this, args);
            this.currentResultTimer = 0;
            this.currentResultFadeId = 0;
         },
         postscript: function(args)
         {
            this.inherited(arguments);
      
            this.own(
               topic.subscribe("global:AjaxResult", lang.hitch(this, this.addResult)),
               topic.subscribe("global:AjaxError", lang.hitch(this, this.checkError))
            );
         },
         setCurrentResult: function(result)
         {
            this.displayformatedMessageFromResult(result);
            this.currentResult = result;
      
            if(this.currentResultTimer !== 0)
               clearTimeout(this.currentResultTimer);
      
            this.currentResultTimer = setTimeout(lang.hitch(this, this.hideCurrentResult), 3000);
         },
         hideCurrentResult: function()
         {
            this.currentResult = null;
            this.currentResultTimer = 0;
            var fadeArgs = {
               node: dojo.query('div', this.domNode)[0]
            };
            this.currentResultFadeId = dojo.fadeOut(fadeArgs).play();
         },
         displayformatedMessageFromResult: function(result)
         {
            this.domNode.innerHTML = this.formatMessageFromResult(result);
            var fadeArgs = {
               node: dojo.query('div', this.domNode)[0],
               duration: 1
            };
            this.currentResultFadeId = dojo.fadeIn(fadeArgs).play();
         },
         resultOkToPublish: function(result)
         {
            return true;
         }
      });
   }
);
